package com.jingdianjichi.oss.service;


import com.jingdianjichi.oss.adapter.StorageAdapter;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
public class FileService {

    private final StorageAdapter storageAdapter;

    // 构造器，会自动读取Bean，进行注入
    public FileService(StorageAdapter storageAdapter){
        this.storageAdapter = storageAdapter;
    }

    public List<String> getAllBuckets() {
        return storageAdapter.getAllBuckets();
    }


    public String getUrl(String bucketName, String objectName) {
        return storageAdapter.getUrl(bucketName, objectName);
    }

    public String uploadFile(MultipartFile uploadFile, String bucket, String objectName) {
        storageAdapter.uploadFile(uploadFile,bucket,objectName);
        objectName = objectName + "/" + uploadFile.getOriginalFilename();
        return storageAdapter.getUrl(bucket, objectName);

    }
}
